<template>
  <div class="radio">
    <div class="container">
      <div class="topNav">
        <ul class="navList">
          <li class="item" v-for="item in radioCategoryList" :key="item.id">
            <a href="javascript:;" :class="categoryActive === item.name ? 'active' : ''" @click="handleClickCategory(item)" :style="{backgroundImage: `url(${item.picWebUrl})`}">
              <span>{{item.name}}</span>
            </a>
          </li>
        </ul>
        <div class="content" v-if="radioList.length">
          <RadioCard :radioList="radioList" :title="categoryActive"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import RadioCard from '../../components/RadioCard'
export default {
  name: 'Radio',
  components: {
    RadioCard
  },
  data () {
    return {
      radioCategoryList: [], // 电台分类列表
      categoryActive: '推荐',
      radioList: []
    }
  },
  methods: {
    // 获取电台分类
    async getRadioCategoryList () {
      const res = await this.$http.get('/dj/catelist')
      this.radioCategoryList = res.data.categories
      this.getRadioRecommend()
    },
    // 处理电台分类点击事件
    handleClickCategory (target) {
      this.categoryActive = target.name
      this.getRadio(target.id)
    },
    // 获取分类的详情
    async getRadio (cateId) {
      const res = await this.$http.get(`/dj/radio/hot?cateId=${cateId}`)
      this.radioList = res.data.djRadios
    },
    // 获取电台首页推荐
    async getRadioRecommend () {
      const res = await this.$http.get('/dj/recommend')
      this.radioList = res.data.djRadios
    }
  },
  created () {
    this.getRadioCategoryList()
  }
}
</script>

<style lang="less" scoped>
.radio{
  margin-top: 33px;
}
.container{
  width: 1100px;
  margin: 0 auto;
  background-color: #ffffff;
}

.topNav{
  width: 100%;
  padding: 10px 0;
  .navList{
    width: 100%;
    overflow: hidden;
    .item{
      float: left;
      width: 1100px / 9;
      margin: 10px auto;
      a{
        position: relative;
        display: block;
        width: 50%;
        // height: 60px;
        padding: 45px 0 5px 0;
        margin: 0 auto;
        text-align: center;
        color: #ba9797;
        font-size: 13px;
        background-position: 7px 0;
        background-repeat: no-repeat;
        border: 1px solid #ffffff;
      }
      a:hover{
        background-color: #f6f7f7;
      }
      .active{
        color: #db5e5e;
        border-color: #db5e5e;
        border-radius: 5px;
        background-position: -41px 0;
      }
    }
  }
}
</style>
